package com.rt.cloud.auth.config.login;

import org.springframework.context.ApplicationListener;
import org.springframework.security.authentication.event.AuthenticationFailureBadCredentialsEvent;
import org.springframework.security.authentication.event.AuthenticationSuccessEvent;
import org.springframework.stereotype.Component;

// spring security防止恶意登录: https://blog.csdn.net/neweastsun/article/details/79825188
@Component
public class AuthenticationFailureListener implements ApplicationListener<AuthenticationFailureBadCredentialsEvent> {

    // 登录失败， 这里都会执行
    @Override
    public void onApplicationEvent(AuthenticationFailureBadCredentialsEvent e) {
        //在这里记录登陆失败的次数
        String username = e.getAuthentication().getPrincipal().toString();

        System.out.println("AuthenticationFailureListener:"+ username);


    }

}
